<?PHP
include("../config/connect.php");
include("../public/common.php");

$id = CheckUrlParamNoDie("id");
$tb_id = CheckUrlParamNoDie("tb_id");
$nPage = CheckUrlParamNoDie("page");

if($nPage == "")
	$nPage = 0;
	
if( $id == "" )
{
	echo "error";
	exit;
}
// Normal
$count = mysql_num_rows(mysql_query("select id from order_handle_report where user_id='".$id."'"));
$sumMoney = mysql_result(mysql_query("select sum(commission)*0.6 as tmp from order_handle_report where user_id='".$id."'"), 0, "tmp");

$PAGE_SIZE = 6;
$limit = " limit ". $nPage*$PAGE_SIZE .",$PAGE_SIZE";
$sql = "select a_no,trade_id,opt_time,commission,num_iid,item_title,handle_code,seller_nick from order_handle_report where user_id='".$id."' order by opt_time desc".$limit;
$result = mysql_query( $sql );

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
<!--
body {
	font-size: 12px;
	color: #000;
	font-family: 宋体;
}
</style>
</head>

<body style="margin-left:0; margin-top:0; margin-right:0; margin-bottom:0">
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="2">
      <tr bgcolor="#F4D662">
        <td width="151" height="24" align="center"><strong>序号</strong></td>
        <td width="100" align="center"><strong>商城</strong></td>
        <td width="244" align="center"><strong>返现日期</strong></td>
        <td width="197" align="center"><strong>订单号</strong></td>
        <td width="205" align="center"><strong>返现额</strong></td>
        <td width="200" align="center"><strong>状态</strong></td>
        <td width="100" align="center"><strong>分享到微博</strong></td>
      </tr>
      <?PHP 
	  $i = $PAGE_SIZE * $nPage + 1;
	  if ($count > 0){
	  while( $result && $row = mysql_fetch_assoc( $result )) {
	  ?>
      <tr bgcolor="<?PHP if ($i % 2 == 0) echo "#EAE7BB"; else echo "#EEEEEE" ?>">
        <td height="24" align="center"><?PHP echo $i; ?></td>
        <td align="center"><?PHP if ($row["a_no"] < 100) echo "淘宝"; else echo $row["seller_nick"]; ?></td>
        <td align="center"><?PHP echo $row["opt_time"]; ?></td>
        <td align="center" ><a href="#" title="点击查看商品链接" onclick="OnShowItem(<?PHP echo "'".$row["num_iid"]."',".$row["a_no"]; ?>)"><?PHP echo substr($row["trade_id"], 0, 8)."**".substr($row["trade_id"], 10, 4); ?></a></td>
        <td align="center"><?PHP echo "￥".round($row["commission"] * 0.6, 2); ?></td>
        <td align="center"><?PHP if ($row["handle_code"] == 0) echo "<img src='images/clock.gif'>&nbsp;未返现"; else echo "<img src='images/accept.gif'>&nbsp;已返现"; ?></td>
        <td align="center">
		<?PHP if ($row["a_no"] < 100) { ?>
        <img src="images/share_weibo.gif" style="cursor:pointer" title="把商品信息分享到新浪微博" onclick="OnShare('http://service.weibo.com/share/share.php', <?PHP echo $row["num_iid"].",".round($row["commission"] * 0.6, 2); ?>)" />&nbsp;<img src="images/share_wb_qq.gif" width="16" height="16" style="cursor:pointer" title="把商品信息分享到腾讯微博" onclick="OnShare('http://v.t.qq.com/share/share.php', <?PHP echo $row["num_iid"].",".round($row["commission"] * 0.6, 2); ?>)" />
        <?PHP } ?>
        </td>
  </tr>
      <?PHP
	  $i++;
		}
		}
		else
		{
			echo "<tr><td align='left' colspan=6>暂时没有数据，<a href='http://t.cn/apUxzD' target='_blank'>查看其它用户的返现分享</a></td></tr>";
		}
		?>
</table>
<div>
<table width="100%" cellspacing="4">
  <tr>
<td>&nbsp;购物兔是<strong>返现最快</strong>，最方便的；订单在您<strong>确认收货后30分钟内</strong>就能查到；当天内返款就自动到您的支付宝上了！</td>

<td align="right">
<?PHP if ($count > $PAGE_SIZE) {?>
<a href="?page=0&id=<?PHP echo $id; ?>">首页</a>&nbsp;&nbsp;
<?PHP if ($nPage > 0) {?>
<a href="?page=<?PHP echo $nPage-1; ?>&id=<?PHP echo $id; ?>">上一页</a>&nbsp;&nbsp;
<?PHP } ?>
<?PHP if ($nPage < intval($count / $PAGE_SIZE)) {?>
<a href="?page=<?PHP echo $nPage+1; ?>&id=<?PHP echo $id; ?>">下一页</a>&nbsp;&nbsp;
<?PHP } ?>
<a href="?page=<?PHP echo intval($count / $PAGE_SIZE); ?>&id=<?PHP echo $id; ?>">尾页</a>&nbsp;&nbsp;
<?PHP } ?>
</td>

</tr></table>

</div>

</body>
</html>

<script language="javascript" src="../js/jquery.min.js"></script>  
<script language="javascript">
function GetItemInfo(itemid)
{
	var url = "http://www.gouwutu.com/taobaoapi/get_item_info.php?itemid=" + itemid;
	var res = $.ajax({	url: url,
			async: false
		}).responseText;
//	alert(res);
	var resObj = eval('(' + res + ')');
	return resObj;
}
function AddTubi(itemid)
{
	var url = "http://www.gouwutu.com/funapi/opt_tubi.php?userid=<?PHP echo $id ?>&type=s&itemid=" + itemid;
	var res = $.ajax({	url: url,
			async: false
		}).responseText;
//	alert(res);
}
function OnShare(weibourl, itemid, commission)
{
	var resObj = GetItemInfo(itemid);
	if (resObj.code==0)
	{
		alert("获取商品信息出错，商品可能已经下架。您可以稍后试试。");
		return;
	}
	
	//
	url = weibourl + "?appkey=&title="+encodeURIComponent("#购物兔分享# 我用购物兔在淘宝上购买了“" + resObj.title.substring(0, 50) + "”" + resObj.detail_url+"，返现了 "+commission+" 元，[钱]太爽了！购物兔官网上有介绍，速围观：http://gouwutu.com?ref=wb_e_s") + "&pic="+encodeURIComponent(resObj.pic_url)+"&ralateUid=1972429953";

	window.open(url);
	
	AddTubi(itemid);
}

function OnShowItem(itemid, a_no)
{
	if (a_no >= 100)
	{
		alert("其它商城暂时不支持打开商品链接哦。");
		return;
	}
	
	//
	var resObj = GetItemInfo(itemid);
	if (resObj.code==0)
	{
		alert("无法打开商品链接，商品可能已经下架。");
		return;
	}
	window.open(resObj.detail_url);
}

</script>